package cn.wp.ewallet.wmps.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.wp.common.core.authentication.AuthenticationContext;
import cn.wp.common.core.dto.WpResult;
import cn.wp.common.core.id.Id;
import cn.wp.common.core.util.BeanUtil;
import cn.wp.ewallet.common.model.dto.MoneyTypeInfoDto;
import cn.wp.ewallet.common.service.MoneyTypeInfoService;
import cn.wp.ewallet.wallet.dao.AccountInfoDao;
import cn.wp.ewallet.wallet.dao.AccountLogDao;
import cn.wp.ewallet.wallet.extension.constant.EwalletWalletConstant;
import cn.wp.ewallet.wallet.extension.util.EwalletWalletUtil;
import cn.wp.ewallet.wallet.model.dto.AccountInfoDto;
import cn.wp.ewallet.wallet.model.dto.UserWalletRelDto;
import cn.wp.ewallet.wallet.model.entity.AccountInfoDo;
import cn.wp.ewallet.wallet.model.entity.AccountInfoDoo;
import cn.wp.ewallet.wallet.model.entity.AccountLogDo;
import cn.wp.ewallet.wallet.service.AccountInfoService;
import cn.wp.ewallet.wallet.service.UserWalletRelService;
import cn.wp.ewallet.wmps.dao.*;
import cn.wp.ewallet.wmps.extension.constant.EwalletWmpsConstant;
import cn.wp.ewallet.wmps.model.dto.EarnStatLogDto;
import cn.wp.ewallet.wmps.model.dto.FinaTotalInfoDto;
import cn.wp.ewallet.wmps.model.dto.PurchasedProdOrderRelDetailDto;
import cn.wp.ewallet.wmps.model.dto.TtyStatInfoDto;
import cn.wp.ewallet.wmps.model.entity.*;
import cn.wp.ewallet.wmps.service.EarnStatLogService;
import cn.wp.ewallet.wmps.service.ProdOrderRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import static cn.wp.ewallet.wallet.extension.constant.EwalletWalletConstant.ACCOUNT_TYPE_AVAILABLE;


/**
 * 理财订单-业务逻辑层实现
 * Created by zhangyongli on 2020/01/08
 */
@Service
public class ProdOrderRelServiceImpl implements ProdOrderRelService {

    @Autowired
    private AuthenticationContext authenticationContext;

    @Autowired
    private ProdOrderRelDao prodOrderRelDao;

    @Autowired
    private FinaProdInfoDao finaProdInfoDao;

    @Autowired
    private UserWalletRelService userWalletRelService;

    @Autowired
    private AccountInfoService accountInfoService;

    @Autowired
    private EarnStatLogService earnStatLogService;

    @Autowired
    private FixProdOrderRelDao fixProdOrderRelDao;

    @Autowired
    private FixFinaProdInfoDao fixFinaProdInfoDao;

    @Autowired
    private EarnStatLogDao earnStatLogDao;

    @Autowired
    private FinaProdInfoServiceImpl finaProdInfoServiceImpl;

    @Autowired
    private EarnDetailLogDao earnDetailLogDao;

    @Autowired
    private ReturnYieldInfoDao returnYieldInfoDao;

    @Autowired
    private AccountLogDao accountLogDao;

    @Autowired
    private AccountInfoDao accountInfoDao;

    @Autowired
    private EarlyRedempInfoDao earlyRedempInfoDao;

    @Autowired
    private FinaProdInfoServiceImpl getFinaProdInfoServiceImpl;

    @Autowired
    private MoneyTypeInfoService moneyTypeInfoService;


    @Override
    public BigDecimal getFrozenAmount(String accountId) {
        return prodOrderRelDao.selectFrozenAmount(accountId);
    }

    @Override
    @Transactional
    public WpResult purchaseFinaProd(String finaProdId, BigDecimal purchAmount, String isAutoRenewal, String moneyTypeId) {

        String walletAddress = userWalletRelService.getUserWalletRel().getWalletAddress();
        AccountInfoDoo finaAccountInfoDoo = accountInfoDao.selectAccountByWalletAddMoneyTypeId(walletAddress, EwalletWalletConstant.MONEY_TYPE_SHQC, EwalletWmpsConstant.ACCOUNT_TYPE_FINA);
        String finaAccountId = finaAccountInfoDoo.getAccountId();


        AccountInfoDoo availableAccountInfoDoo = accountInfoDao.selectAccountByWalletAddMoneyTypeId(walletAddress, EwalletWalletConstant.MONEY_TYPE_SHQC, EwalletWmpsConstant.ACCOUNT_TYPE_AVAILABLE);
        BigDecimal purchAmountLower = EwalletWalletUtil.toLowerWei(purchAmount,new BigDecimal(availableAccountInfoDoo.getMoneyTypeUnit()));

        //转账
        if (availableAccountInfoDoo.getMoneyAmount().compareTo(purchAmountLower) == -1) {
            return new WpResult().failure(EwalletWalletConstant.CHECK_AMOUNT_FAILED_CODE, "账户余额不足");
        }
        //保存可用账户资产变动
        accountInfoService.saveAccountChange(walletAddress, purchAmountLower, EwalletWalletConstant.ACCOUNT_SUBTRACT, EwalletWalletConstant.ACCOUNT_CHARGE_CASE_OTHERS, EwalletWalletConstant.MONEY_TYPE_SHQC,  EwalletWmpsConstant.ACCOUNT_TYPE_AVAILABLE);

        //保存理财账户资产变动
        accountInfoService.saveAccountChange(walletAddress, purchAmountLower, EwalletWalletConstant.ACCOUNT_ADD, EwalletWalletConstant.ACCOUNT_CHARGE_CASE_OTHERS, EwalletWalletConstant.MONEY_TYPE_SHQC,  EwalletWmpsConstant.ACCOUNT_TYPE_FINA);

        FinaProdInfoDo finaProdInfoDo = finaProdInfoDao.selectFinaProdInfoById(finaProdId);
        FixFinaProdInfoDo fixFinaProdInfoDo = fixFinaProdInfoDao.selectfixFinaProdInfo(finaProdId);

        BigDecimal finaProdCycle = fixFinaProdInfoDo.getFinaProdCycle();
        int returnRateCycle;
        if(EwalletWmpsConstant.RETURN_RATE_CYCLE_QUARTER.equals(finaProdInfoDo.getReturnRateCycle())) {
            returnRateCycle = 90;
        }else {
            returnRateCycle = 1;
        }
        BigDecimal yieldRate = finaProdInfoDo.getYieldRate();
        //预计总收益
        BigDecimal earnAmount = purchAmountLower.multiply(yieldRate).multiply(finaProdCycle.divide(BigDecimal.valueOf(EwalletWmpsConstant.CYCLE_YEAR), 8,BigDecimal.ROUND_HALF_UP));
        //日息 = （本金*年化收益率*（理财周期/365））/ 理财周期
        BigDecimal dailyReturnAmount = earnAmount.divide(finaProdCycle, 8, BigDecimal.ROUND_HALF_UP);
        //购买时间
        LocalDateTime purchTime = LocalDateTime.now();
        //生效日期
        LocalDate effDate = null;
        if (purchTime.getHour() >= 15) {
            effDate = LocalDate.now().plusDays(2);
        } else {
            effDate = LocalDate.now().plusDays(1);
        }

        //到期日期
        LocalDate expDate = effDate.plusDays(finaProdCycle.longValue());

        //生成理财产品订单
        ProdOrderRelDo prodOrderRelDo = saveProdOrderRel(finaProdId, purchAmountLower, finaAccountId, effDate);

        //生成定期理财产品订单
        saveFixProdOrderRel(isAutoRenewal, earnAmount, dailyReturnAmount, expDate, prodOrderRelDo);
        //生成返息周期表
        getReturnYieldInfoDo(finaProdCycle, returnRateCycle, dailyReturnAmount, effDate, expDate, prodOrderRelDo);

        return new WpResult().success(true);

    }

    private void saveFixProdOrderRel(String isAutoRenewal, BigDecimal earnAmount, BigDecimal dailyReturnAmount, LocalDate expDate, ProdOrderRelDo prodOrderRelDo) {
        FixProdOrderRelDo fixProdOrderRelDo = new FixProdOrderRelDo();
        fixProdOrderRelDo.setProdOrderId(prodOrderRelDo.getProdOrderId());
        fixProdOrderRelDo.setRecYield(earnAmount);
        fixProdOrderRelDo.setDailyReturnAmount(dailyReturnAmount);
        fixProdOrderRelDo.setActualYield(new BigDecimal(0));
        fixProdOrderRelDo.setExpTime(Date.from(expDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        fixProdOrderRelDo.setIsAutoRenewal(isAutoRenewal);
        fixProdOrderRelDao.saveFixProdOrderRel(fixProdOrderRelDo);
    }

    private ProdOrderRelDo saveProdOrderRel(String finaProdId, BigDecimal purchAmount, String finaAccountId, LocalDate effDate) {
        ProdOrderRelDo prodOrderRelDo = new ProdOrderRelDo();
        prodOrderRelDo.setProdOrderId(Id.gen());
        prodOrderRelDo.setFinaProdId(finaProdId);
        prodOrderRelDo.setAccountId(finaAccountId);
        prodOrderRelDo.setPurchAmount(purchAmount);
        prodOrderRelDo.setPurchTime(new DateTime());
        prodOrderRelDo.setEffDate(Date.from(effDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        prodOrderRelDo.setOrderStatus(EwalletWmpsConstant.ORDER_STATUS_WAITING);
        prodOrderRelDo.setStatusTime(new Date());
        prodOrderRelDao.insertProdOrderRel(prodOrderRelDo);
        return prodOrderRelDo;
    }

    @Override
    public void getReturnYieldInfoDo(BigDecimal finaProdCycle, int returnRateCycle, BigDecimal dailyReturnAmount, LocalDate effDate, LocalDate expDate, ProdOrderRelDo prodOrderRelDo) {
        LocalDate returnDate = effDate.plusDays(returnRateCycle+1);
        LocalDate lastReturnDate = expDate;

        //返期周期总数
        int cycle = finaProdCycle.intValue() / returnRateCycle;
        //余数
        int days = finaProdCycle.intValue() % returnRateCycle;
        //余数大于0时，返期周期总数-1，余下的天数另外计算
        if (days > 0) {
            cycle = cycle - 1;
        }
        for (int i = 0; i < cycle; i++) {
            lastReturnDate = returnDate;
            //生成返息周期表
            ReturnYieldInfoDo returnYieldInfoDo = new ReturnYieldInfoDo();
            returnYieldInfoDo.setReturnYieldId(Id.gen());
            returnYieldInfoDo.setProdOrderId(prodOrderRelDo.getProdOrderId());
            returnYieldInfoDo.setReturnDate(Date.from(returnDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            BigDecimal returnYield = dailyReturnAmount.multiply(new BigDecimal(returnRateCycle));
            returnYieldInfoDo.setReturnYield(returnYield);
            returnYieldInfoDo.setReturnStatus(EwalletWmpsConstant.RETURN_STATUS_WATT);
            returnYieldInfoDo.setStatusTime(new Date());

            returnYieldInfoDao.saveReturnYieldInfo(returnYieldInfoDo);
            LocalDate localDate = returnDate.plusDays(returnRateCycle);
            returnDate = localDate;
        }
        if (days > 0) {
            //生成返息周期表
            ReturnYieldInfoDo returnYieldInfoDo = new ReturnYieldInfoDo();
            returnYieldInfoDo.setReturnYieldId(Id.gen());
            returnYieldInfoDo.setProdOrderId(prodOrderRelDo.getProdOrderId());
            returnYieldInfoDo.setReturnDate(Date.from(expDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            BigDecimal returnYield = dailyReturnAmount.multiply(BigDecimal.valueOf(days + returnRateCycle));
            returnYieldInfoDo.setReturnYield(returnYield);
            returnYieldInfoDo.setReturnStatus(EwalletWmpsConstant.RETURN_STATUS_WATT);
            returnYieldInfoDo.setStatusTime(new Date());
            returnYieldInfoDao.saveReturnYieldInfo(returnYieldInfoDo);
        }
    }

    @Override
    public PurchasedProdOrderRelDetailDto getProdDetailInfoByOrderRelId(String prodOrderRelId) {
        PurchasedProdOrderRelDetailDto purchasedProdOrderRelDetailDto = new PurchasedProdOrderRelDetailDto();
        List<ReturnYieldInfoDo> returnYieldInfoDos = returnYieldInfoDao.selectReturnYieldInfoList(prodOrderRelId);
        List<Date> returnDates = new ArrayList<>();
        for (ReturnYieldInfoDo returnYieldInfoDo : returnYieldInfoDos) {
            Date date = returnYieldInfoDo.getReturnDate();
            returnDates.add(date);
        }
        purchasedProdOrderRelDetailDto.setReturnDates(returnDates);


        MoneyTypeInfoDto moneyTypeInfoDto = moneyTypeInfoService.getMoneyTypeInfoByMoneyTypeId(EwalletWalletConstant.MONEY_TYPE_SHQC);
        PurchasedProdOrderRelDoo purchasedProdOrderRelDoo = prodOrderRelDao.selectProdOrderRelDetailByProdOrderRelId(prodOrderRelId);
        Date effDate = purchasedProdOrderRelDoo.getEffDate();

        if (null != purchasedProdOrderRelDoo) {
            purchasedProdOrderRelDetailDto.setFinaProdName(purchasedProdOrderRelDoo.getFinaProdName());
            purchasedProdOrderRelDetailDto.setEffDate(DateUtil.formatDateTime(effDate));
            purchasedProdOrderRelDetailDto.setFrozenAmount(EwalletWalletUtil.toUpperWei(purchasedProdOrderRelDoo.getPurchAmount(), new BigDecimal(moneyTypeInfoDto.getMoneyTypeUnit())));
            purchasedProdOrderRelDetailDto.setPurchAmount(EwalletWalletUtil.toUpperWei(purchasedProdOrderRelDoo.getPurchAmount(), new BigDecimal(moneyTypeInfoDto.getMoneyTypeUnit())));
            purchasedProdOrderRelDetailDto.setPurchTime(DateUtil.formatDateTime(purchasedProdOrderRelDoo.getPurchTime()));
            purchasedProdOrderRelDetailDto.setIsAutoRenewal(purchasedProdOrderRelDoo.getIsAutoRenewal());
            purchasedProdOrderRelDetailDto.setProdOrderId(purchasedProdOrderRelDoo.getProdOrderId());
            purchasedProdOrderRelDetailDto.setFinaProdId(purchasedProdOrderRelDoo.getFinaProdId());
            if (DateUtil.isSameDay(new Date(), effDate) || DateUtil.isIn(new Date(), effDate, purchasedProdOrderRelDoo.getExpTime())) {
                long laveDays = getFinaProdInfoServiceImpl.differentDays(new Date(),purchasedProdOrderRelDoo.getExpTime());
                purchasedProdOrderRelDetailDto.setLaveDays(laveDays);
            }
        }
        BigDecimal freePeriod = purchasedProdOrderRelDoo.getFreePeriod();
        Calendar calendar = DateUtil.calendar(effDate);
        calendar.add(Calendar.DATE, freePeriod.intValue());

        if(DateUtil.isIn(new Date(), calendar.getTime(), purchasedProdOrderRelDoo.getExpTime())){
            purchasedProdOrderRelDetailDto.setIsDuringFreeze(true);
        }else {
            purchasedProdOrderRelDetailDto.setIsDuringFreeze(false);
        }

        return purchasedProdOrderRelDetailDto;
    }

    @Override
    public FinaTotalInfoDto getPersonalTotal() {
        FinaTotalInfoDto finaTotalInfoDto = new FinaTotalInfoDto();
        UserWalletRelDto userWalletRelDto = userWalletRelService.getUserWalletRel();
        if (null == userWalletRelDto) {
            return null;
        }

        //查询SHQC账户信息
        AccountInfoDto shqcAccountInfo = accountInfoService.selectAccountByWalletAddMoneyTypeId(userWalletRelDto.getWalletAddress(), EwalletWalletConstant.MONEY_TYPE_SHQC, ACCOUNT_TYPE_AVAILABLE);
        //SQHC数据精度
        BigDecimal unit = BigDecimal.valueOf(Double.valueOf(shqcAccountInfo.getMoneyTypeUnit()));
        //理财总额
        BigDecimal finaTotal = accountInfoService.selectFinaMoneyAmount(userWalletRelDto.getWalletAddress(), EwalletWalletConstant.MONEY_TYPE_SHQC);
        if (null != finaTotal) {
            finaTotalInfoDto.setTotal(EwalletWalletUtil.toUpperWei(finaTotal, unit));
        }

        //总收益
        EarnStatLogDto earnStatLogDto = earnStatLogService.getLatestEarnStatLog(userWalletRelDto.getWalletAddress());

        if (null != earnStatLogDto) {
            finaTotalInfoDto.setTotalEarn(EwalletWalletUtil.toUpperWei(earnStatLogDto.getTotalEarn(), unit));
        }
        //昨日收益
        EarnStatLogDto yesEarnStatLog = earnStatLogService.getEarnStatLogByDate(userWalletRelDto.getWalletAddress(), LocalDate.now().minusDays(2).toString());
        if (null != earnStatLogDto && null != yesEarnStatLog) {
            finaTotalInfoDto.setYesterdayEarn(EwalletWalletUtil.toUpperWei(earnStatLogDto.getTotalEarn().subtract(yesEarnStatLog.getTotalEarn()), unit));
        }

        return finaTotalInfoDto;
    }

    @Override
    public void modifyRenewalStatus(String prodOrderId, String status) {
        FixProdOrderRelDo fixProdOrderRelDo = fixProdOrderRelDao.selectFixProdOrderRelByProdOrderId(prodOrderId);
        fixProdOrderRelDo.setIsAutoRenewal(status);
        fixProdOrderRelDao.updateFixProdOrderRel(fixProdOrderRelDo);
    }

    @Override
    @Transactional
    public WpResult earlRedemption(String prodOrderId, String finaProdId) {

        FixFinaProdInfoDo fixFinaProdInfoDo = fixFinaProdInfoDao.selectfixFinaProdInfo(finaProdId);
        if (fixFinaProdInfoDo.getIsEarlyRedemp().equals(EwalletWmpsConstant.NO_EARLY_REDEMP)) {
            return new WpResult().failure("该理财产品不能提前赎回");
        } else {
            //可以提前赎回
            //查询该订单下的数量
            //更新理财订单状态
            ProdOrderRelDo prodOrderRelDo = prodOrderRelDao.selectProdOrderRelByProdOrderId(prodOrderId);
            prodOrderRelDo.setOrderStatus(EwalletWmpsConstant.ORDER_STATUS_STOP);
            prodOrderRelDao.updateProdOrderRelDo(prodOrderRelDo);
            //SHQC可用资金账户
            String walletAddress = userWalletRelService.getUserWalletRel().getWalletAddress();

            //保存可用账户资产变动信息
            BigDecimal balance = fixFinaProdInfoDo.getDiscountRate().multiply(prodOrderRelDo.getPurchAmount());
            accountInfoService.saveAccountChange(walletAddress, balance, EwalletWalletConstant.ACCOUNT_ADD, EwalletWalletConstant.ACCOUNT_CHARGE_CASE_OTHERS, EwalletWalletConstant.MONEY_TYPE_SHQC,EwalletWalletConstant.ACCOUNT_TYPE_AVAILABLE);

            //保存定期理财账户变更记录
            accountInfoService.saveAccountChange(walletAddress, prodOrderRelDo.getPurchAmount(), EwalletWalletConstant.ACCOUNT_SUBTRACT, EwalletWalletConstant.ACCOUNT_CHARGE_CASE_OTHERS, EwalletWalletConstant.MONEY_TYPE_SHQC,EwalletWalletConstant.ACCOUNT_TYPE_REGULAR);

            //记录提前赎回
            createEarlyRedempInfo(prodOrderId, fixFinaProdInfoDo, prodOrderRelDo);
            //更新收益明细记录待反状态为不返还
            List<EarnDetailLogDo> earnDetailLogDos = earnDetailLogDao.selectEarnDetailLogByProIdAndStatus(prodOrderId, EwalletWmpsConstant.RETURN_STATUS_WATT);
            for (int i = 0; i < earnDetailLogDos.size(); i++) {
                EarnDetailLogDo earnDetailLogDo = earnDetailLogDos.get(i);
                earnDetailLogDo.setEarnStatus(EwalletWmpsConstant.RETURN_STATUS_NO);
            }
            earnDetailLogDao.updateBabch(earnDetailLogDos);
            //更新待返回利息周期为不返还
            List<ReturnYieldInfoDo> returnYieldInfoDos = returnYieldInfoDao.selectReturnYieldInfoWaitList(prodOrderId);
            for (int i = 0; i < returnYieldInfoDos.size(); i++) {
                ReturnYieldInfoDo returnYieldInfoDo = returnYieldInfoDos.get(i);
                returnYieldInfoDo.setReturnStatus(EwalletWmpsConstant.RETURN_STATUS_NO);
            }
            returnYieldInfoDao.updateBanch(returnYieldInfoDos);
            return new WpResult().success();
        }

    }


    @Override
    public TtyStatInfoDto getTtyStatInfo() {
        //返回数据
        TtyStatInfoDto ttyStatInfoDto = new TtyStatInfoDto();

        String walletAddress = userWalletRelService.getUserWalletRel().getWalletAddress();
        //T-2天收益统计信息
        EarnStatLogDto earnStatLogByYestDate = earnStatLogService.getEarnStatLogByDate(walletAddress, LocalDate.now().minusDays(2).toString());
        //T-1天收益信息
        EarnStatLogDto earnStatLogByTodayDate = earnStatLogService.getEarnStatLogByDate(walletAddress, LocalDate.now().minusDays(1).toString());
        BigDecimal yestTtyEarn = null;
        BigDecimal totalEarn = null;
        //天天盈总收益
        if (null != earnStatLogByTodayDate) {
            totalEarn = earnStatLogByTodayDate.getTtyTotalEarn();
        }
        //天天盈昨日收益
        if (null != earnStatLogByYestDate && null != earnStatLogByTodayDate) {
            yestTtyEarn = earnStatLogByTodayDate.getTtyTotalEarn().subtract(earnStatLogByYestDate.getTtyTotalEarn());
        }
        //查询账户
        AccountInfoDo accountInfoDo = accountInfoService.selectAccountByWalletAddAccountType(walletAddress, EwalletWmpsConstant.ACCOUNT_TYPE_DAILY);
        //根据账户id查询理财产品订购单

        //获取SHQC数据精度
        MoneyTypeInfoDto moneyTypeInfoDto = moneyTypeInfoService.getMoneyTypeInfoByMoneyTypeId(EwalletWalletConstant.MONEY_TYPE_SHQC);
        BigDecimal shqcUnit = BigDecimal.valueOf(Long.valueOf(moneyTypeInfoDto.getMoneyTypeUnit()));

        ttyStatInfoDto.setAccountId(accountInfoDo.getAccountId());
        ttyStatInfoDto.setMoneyAmount(EwalletWalletUtil.toUpperWei(accountInfoDo.getMoneyAmount(), shqcUnit));
        ttyStatInfoDto.setYestTtyEarn(EwalletWalletUtil.toUpperWei(yestTtyEarn, shqcUnit));
        ttyStatInfoDto.setTtyTotalEarn(EwalletWalletUtil.toUpperWei(totalEarn, shqcUnit));
        List<FinaProdInfoDo> list = finaProdInfoDao.selectFinaProdInfoByProcType(EwalletWmpsConstant.PROD_TYPE_DAILY);
        if (CollectionUtil.isNotEmpty(list)) {
            ttyStatInfoDto.setYieldRate(list.get(0).getYieldRate());
        }
        return ttyStatInfoDto;
    }

    private void createEarlyRedempInfo(String prodOrderId, FixFinaProdInfoDo fixFinaProdInfoDo, ProdOrderRelDo prodOrderRelDo) {
        //生成提前赎回
        EarlyRedempInfoDo earlyRedempInfoDo = new EarlyRedempInfoDo();
        earlyRedempInfoDo.setProdOrderId(prodOrderId);
        earlyRedempInfoDo.setRedempAmount(prodOrderRelDo.getPurchAmount());
        earlyRedempInfoDo.setLossAmount(prodOrderRelDo.getPurchAmount().subtract(prodOrderRelDo.getPurchAmount().multiply(fixFinaProdInfoDo.getDiscountRate())));
        earlyRedempInfoDo.setRedempTime(new Date());
        earlyRedempInfoDao.insert(earlyRedempInfoDo);
    }

}
